# -*- coding: utf-8 -*-
from flask import Flask
from flask_script import Manager
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail
from flask_apscheduler import APScheduler
import json, requests
import os
import flask_excel as excel

app = Flask( __name__ )

manager = Manager( app )

app.config.from_pyfile( "config/base_setting.py" )




if "ops_config" in os.environ:
    app.config.from_pyfile( "config/%s_setting.py"%( os.environ['ops_config'] ) )

db = SQLAlchemy( app )

mail = Mail(app)  # 创建邮件类对象

excel.init_excel(app)


# 定时器

class Config(object):
    SCHEDULER_TIMEZONE = 'Asia/Shanghai'  # 配置时区
    SCHEDULER_API_ENABLED = True  # 添加API

scheduler=APScheduler()

@scheduler.task('cron', id='task', month='*',day=26)
def task():
    send = requests.get("http://101.132.227.54:82/api/check/autosyncheck")
    print('同步考勤信息')

@scheduler.task('cron', id='task2', month='*',day=1,hour=9)
def task2():
    send = requests.get("http://101.132.227.54:82/api/report/sendreport")
    print('发送人力月报')

@scheduler.task('cron', id='task3',day='*',hour=9)
def task3():
    send = requests.get("http://101.132.227.54:82/api/member/postemployUser")
    print('发送人员考核提醒')

# @scheduler.task('cron', id='task2', minute='*')
# def task2():
#     send = requests.get("http://127.0.0.1:82/api/check/syncheck1")
#     print('同步考勤信息')

app.config.from_object(Config())
scheduler.init_app(app)
scheduler.start()



